package commons.monitor;

import java.util.ArrayList;
import java.util.Collection;

import com.amazonaws.services.cloudwatch.AmazonCloudWatch;
import com.amazonaws.services.cloudwatch.model.Dimension;
import com.amazonaws.services.cloudwatch.model.MetricDatum;
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest;

public class InternalMonitor {
	
	private static InternalMonitor monitor;
	private AmazonCloudWatch cloudWatch;
	
	private InternalMonitor() {
		cloudWatch = CloudWatchReceiver.getMonitor();	
	}
	
	public static InternalMonitor getInternalMonitor() {
		if(monitor == null) {
			monitor = new InternalMonitor();
		} return monitor;
	}
	
	public void putMetricIntoCloudWatch(NewMetric metric) {
		PutMetricDataRequest newMetric = new PutMetricDataRequest();
		
		//see how this works in practice
		MetricDatum datum = new MetricDatum().withDimensions(new Dimension().withName(metric.getName())
				                             .withValue(metric.getValue().toString()));
		
		Collection<MetricDatum> metricData = new ArrayList<MetricDatum>();
		metricData.add(datum);
		newMetric.setMetricData(metricData);
		
		cloudWatch.putMetricData(newMetric);
	}
}
